package com.lovo.practice_7_11;

import java.util.*;

/**
 * 斗地主类
 */
public class DouDIZhu {
    ArrayList<Card> list = new ArrayList();
    List list1 = new ArrayList();
    List list2 = new ArrayList();
    List list3 = new ArrayList();
    List list4 = new ArrayList();
    String[] arr = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

    //初始化扑克
    public void init() {
        for (int i = 3; i <= 15; i++) {
            list.add(new Card(arr[i - 3], "♠", i));
            list.add(new Card(arr[i - 3], "♥", i));
            list.add(new Card(arr[i - 3], "♣", i));
            list.add(new Card(arr[i - 3], "♦", i));
        }
        list.add(new Card("joker", "🤡", 19));
        list.add(new Card("JOKER", "🤡", 20));
    }

    //洗牌
    public void XiPai() {
        Collections.shuffle(list);
    }

    //发牌
    public void Fapai() {
        list1 = list.subList(0, 17);
        list2 = list.subList(17, 34);
        list3 = list.subList(34, 51);
        list4 = list.subList(51, 54);
        System.out.print("玩家一：");
        for (Object i : list1) {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.print("玩家二：");
        for (Object i : list2) {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.print("玩家三：");
        for (Object i : list3) {
            System.out.print(i+" ");
        }
    }

    //理牌
    public void LiPai() {
        list1.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getNumber() - o2.getNumber();
            }
        });
        System.out.println();
        System.out.println("理牌后");
        System.out.print("玩家一：");
        for (Object i : list1) {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.print("玩家二：");
        for (Object i : list2) {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.print("玩家三：");
        for (Object i : list3) {
            System.out.print(i+" ");
        }
    }

    //main
    public static void main(String[] args) {
        DouDIZhu douDIZhu = new DouDIZhu();
        douDIZhu.init();
        douDIZhu.XiPai();

        douDIZhu.Fapai();
        douDIZhu.LiPai();
    }
}




